<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-item label="司机姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['sijiName']" placeholder="请输入司机姓名"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="司机电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['phone']" placeholder="请输入司机电话"  ></a-input>
            </a-form-item>
          </a-col>
         <!-- <a-col :span="24">
            <a-form-item label="车辆类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['cheliangleixing']" placeholder="请输入车辆类型"  ></a-input>
            </a-form-item>
          </a-col>-->
          <!--<a-col :span="24">
            <a-form-item label="排放标准" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['paifangbiaozhun', validatorRules.paifangbiaozhun]" :trigger-change="true"
                                 dictCode="paifangleixing" placeholder="请选择排放标准" />
            </a-form-item>
          </a-col>-->
          <a-col :span="24">
            <a-form-item label="车牌号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['plantNo']" placeholder="请输入车牌号"  ></a-input>
            </a-form-item>
          </a-col>
          <!--<a-col :span="24">
            <a-form-item label="vin号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['vin']" placeholder="请输入vin号"  ></a-input>
            </a-form-item>
          </a-col>-->
          <a-col :span="24">
            <a-form-item label="身份证" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['idCardNo']" placeholder="请输入身份证"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="运输类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['yunshuStatus', validatorRules.yunshuStatus]" :trigger-change="true"
                                 dictCode="yslx" placeholder="请选择运输类型" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="运输货物" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['goodsName']" placeholder="请输货物名称"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="货物重量" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zhongliang']" placeholder="请输入货物重量"  ></a-input>
            </a-form-item>
          </a-col>
         <!-- <a-col :span="24">
            <a-form-item label="访问部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-depart v-decorator="['yuyuedept']" multi  />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="被访人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-user-by-dep v-decorator="['beifangren']" />
            </a-form-item>
          </a-col>-->
          <!--<a-col :span="24">
            <a-form-item label="预约人电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['yuyuephone']" placeholder="请输入预约人电话"  ></a-input>
            </a-form-item>
          </a-col>-->
          <a-col :span="24">
            <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea v-decorator="['tag']" rows="4" placeholder="请输入备注" />
            </a-form-item>
          </a-col>
          <!--<a-col :span="24">
            <a-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zhuangtai']" placeholder="请输入状态"  ></a-input>
            </a-form-item>
          </a-col>-->
          <a-col :span="24">
            <a-form-item label="预约时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择预约时间" v-decorator="['yuyueshijian']"
                      :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" :trigger-change="true" style="width: 100%" />
            </a-form-item>
          </a-col>
         <!-- <a-col :span="24">
            <a-form-item label="图片1" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-image-upload isMultiple  v-decorator="['image1']" ></j-image-upload>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="图片2" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-image-upload isMultiple  v-decorator="['image2']" ></j-image-upload>
            </a-form-item>
          </a-col>-->
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'YzdSijiguanliForm',
    components: {
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/SiJiGuanLi/yzdSijiguanli/add",
          edit: "/SiJiGuanLi/yzdSijiguanli/edit",
          queryById: "/SiJiGuanLi/yzdSijiguanli/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'sijiName','phone','cheliangleixing','paifangbiaozhun','plantNo','vin','idCardNo','yuyueren','yuyuephone','tag','zhuangtai','yuyueshijian','image1','image2','goodsName','zhongliang','yunshuStatus'))
        })
      },
      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'sijiName','phone','cheliangleixing','paifangbiaozhun','plantNo','vin','idCardNo','yuyueren','yuyuephone','tag','zhuangtai','yuyueshijian','image1','image2','goodsName','zhongliang','yunshuStatus'))
      },
    }
  }
</script>